

<script
	type="text/javascript"
	src="content/tiny_mce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">

 tinyMCE.init({
 language: "fr",
 mode : "textareas",
 theme : "advanced",
 skin : "o2k7",
 skin_variant : "black",

 
 // Theme options
 theme_advanced_buttons1 : "code,image,|,bold,italic,u,underline,strikethrough,|,outdent,indent,blockquote,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,forecolor,backcolor",
 theme_advanced_buttons2 : "",
 theme_advanced_buttons3 : "",
 theme_advanced_buttons4 : "",

 theme_advanced_toolbar_location : "top",
 theme_advanced_toolbar_align : "left",
 theme_advanced_statusbar_location : "bottom",
 theme_advanced_resizing : true,

 
 valid_elements : "strong/b,underline/u,p,-ol,-ul,-li,a[href|target=_blank|title],span[style=\"text-decoration: underline;\"]",
 entity_encoding : "raw",

 plugins :"paste",
 paste_auto_cleanup_on_paste : true,
 paste_remove_styles: true,
 paste_remove_styles_if_webkit: true,
 paste_strip_class_attributes: true,
 plugins : 'inlinepopups',

 // Style formats
 style_formats : [
 {title : 'Titre', block : 'h3'},
 ],

 setup : function(ed) {
 // Add a custom button
 ed.addButton('mybutton', {
 title : 'My button',
 image : 'img/example.gif',
 onclick : function() {
 // Add you own code to execute something on click
 ed.focus();
 ed.selection.setContent('Hello world!');
 }
 });
 }
 });

 </script>


<script>

function afficheId(baliseId)
  {

  if (document.getElementById && document.getElementById(baliseId) != null)
    {
    document.getElementById(baliseId).style.visibility='visible';
    document.getElementById(baliseId).style.display='block';
    }
  }

function cacheId(baliseId)
  {
  if (document.getElementById && document.getElementById(baliseId) != null)
    {
    document.getElementById(baliseId).style.visibility='hidden';
    document.getElementById(baliseId).style.display='none';
    }
  }


cacheId('cadre_reponses');
// si JavaScript est disponible, cache le contenu dès le
// chargement de la page. Sans JavaScript, le contenu sera
// affiché.
 
</script>

<?php
$idq= recuperer_variable("idq", "");
$id= recuperer_variable("id", "");
$etat = recuperer_variable("etat" ,"" );

/****************************************************************************************/
/*                                definition pagination                                 */
/****************************************************************************************/
$messagesParPage=10; //5 messages par page.

if(isset($_GET['lang'])) // Si la variable $_GET['page'] existe...
{
	$retour_total=mysql_query('SELECT COUNT(*) AS total FROM reponses WHERE id_question ='.$idq); //Nous récupérons le contenu de la requête dans $retour_total
}


$retour_total=mysql_query('SELECT COUNT(*) AS total FROM reponses');
$donnees_total=mysql_fetch_assoc($retour_total);
$total=$donnees_total['total'];


$nombreDePages=ceil($total/$messagesParPage);//nombre de pages

if(isset($_GET['page'])) // Si la variable $_GET['page'] existe...
{
	$pageActuelle=intval($_GET['page']);

	if($pageActuelle>$nombreDePages) // Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages...
	{
		$pageActuelle=$nombreDePages;
	}
}
else // Sinon
{
	$pageActuelle=1; // La page actuelle est la n°1 
}

$premiereEntree=($pageActuelle-1)*$messagesParPage; // On calcul la première entrée à lire

?>


<!--  start page-heading -->
<div id="page-heading">
<h1>Vos dernières questions</h1>
</div>
<!-- end page-heading -->

<table border="0" width="100%" cellpadding="0" cellspacing="0"
	id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img
			src="images/shared/side_shadowleft.jpg" width="20" height="300"
			alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img
			src="images/shared/side_shadowright.jpg" width="20" height="300"
			alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td><!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner"><!--  start table-content  -->
		<div id="table-content_question"><?php
		$connexion=sql_connecter();

		if(isset($_GET['idq'])) // Si la variable $_GET['page'] existe...
		{
			$requete ='SELECT * FROM questions  WHERE id_question='.$idq;
		}

		//die ($requete);
		$result = sql_executer($connexion,$requete);
		while ($donnees = mysql_fetch_array($result))
		{
			$user=$donnees['id_user'];
			$id_question=$donnees['id_question'];
			$contenu_question=$donnees['contenu_question'];
			$titre_question=$donnees['titre_question'];
			$date_question=$donnees['date_question'];

			printf("<div id=\"cat_avatar\">"); //debut cat avatar

			$requete3 ="SELECT path_avatar FROM avatars, users, questions WHERE avatars.id_avatar=users.id_avatar ";
			$requete3 .=" AND users.id_user=".$user;
			$result3 = sql_executer($connexion,$requete3);
			$donnees3=mysql_fetch_array($result3);
			$avatar=$donnees3['path_avatar'];

			$requete4 ="SELECT pseudo_user FROM users WHERE id_user =".$user ;
			$result4 = sql_executer($connexion,$requete4);
			$donnees4=mysql_fetch_array($result4);
			$pseudo_user=$donnees4['pseudo_user'];


			printf("<center>$pseudo_user</center><br />");

			printf("<img src=\"$avatar \">");
			printf("<p><center>Message : 4</center></p>");
			printf("</div>"); // fin cat avatar

			printf("<div id=\"cadre_question\" >");
			printf("<span class=\"titre_question\">");
			printf("<h4>");
			printf("Qui sait ".htmlspecialchars($titre_question)."?");
			printf("</h4> ");
			printf("</span> ");
			printf("<span class=\"date_create\">");
			printf("<p id=\"\" class=\"post-meta\">");
			printf("<em>le $date_question<br /></em>");
			printf("</p>");
			printf("</span>");
			printf("<div class=\"texte\">");
			printf("<br />");
			printf("<p>");
			printf(htmlspecialchars($contenu_question));
			printf("<br /><br /><span class=\"tags\">");
			$requete5 ="SELECT libelle_tag FROM tags, questions_tags WHERE tags.id_tag=questions_tags.id_tag ";
			$requete5 .=" AND questions_tags.id_question =".$id_question ;
			//die($requete5);
			$result5 = sql_executer($connexion,$requete5);
			while($donnees5=mysql_fetch_array($result5))
			{
				$libelle_tag=$donnees5['libelle_tag'];
				printf("<a href=\"\">$libelle_tag</a>");
			}
			printf("</span>\n");
			$requete6="SELECT * FROM reponses WHERE id_question=".$id_question." AND etat_reponse = 1";
			$resultat6=sql_executer($connexion, $requete6);
			if ($donnees6=sql_nombre_lignes($resultat6) > 0){
				printf("<br /><br /><input type=\"submit\" value=\"Voir les réponses\" class=\"bouton_warning\" valign=\"top\" OnClick=\"afficheId('cadre_reponses')\">");
			}
			else {
				printf("<br /><br /><p><h1><i>Aucune réponse</i></h1></p>");

			}
			printf("<div id=\"cadre_reponses\">");
			while($donnees6=mysql_fetch_array($resultat6))
			{
				$id_user=$donnees6['id_user'];
				$id_reponse=$donnees6['id_reponse'];
				$id_question=$donnees6['id_question'];
				$contenu_reponse=$donnees6['contenu_reponse'];
				$date_reponse=$donnees6['date_reponse'];

				$requete7="SELECT pseudo_user FROM users WHERE id_user=".$id_user;
				$resultat7=sql_executer($connexion, $requete7);
				$ligne_7=sql_lire_ligne_tableau($resultat7);
				$pseudo_user2=$ligne_7['pseudo_user'];

				printf("<div id=\"cadre_reponse\">");
				printf("<span class=\"titre_question\">");
				printf("<h4>");
				printf("Réponse de <a href=\"\">$pseudo_user2 </a>");
				printf("</h4> ");
				printf("</span> ");
				printf("<span class=\"date_create\">");
				printf("<p id=\"\" class=\"post-meta\">");
				printf("<em>le $date_reponse<br /></em>");
				printf("</p>");
				printf("</span>");
				printf("<div class=\"texte\">");
				printf("<br />");
				printf("<p>");
				printf(htmlspecialchars($contenu_reponse));
				printf("<br /<br /><br /><a href=\"$page_lire_question&idq=$id_question\">Répondre  &rarr;</a>\n");
				printf("</p>");
				printf("</div>");
				printf("</div>");

			}
			printf("</div>");
			printf("<br /><br /><input type=\"submit\" value=\"Masquer les réponses\" class=\"bouton_warning\" valign=\"top\" OnClick=\"cacheId('cadre_reponses')\">");
			printf("<div id=\"cadre_tiny\">");
			if(isset($_SESSION['login']))
			{
				printf("<br /><br /><form name=\"formulaire\" action=\"$page_lire_question&idq=$id_question&etat=send\" method=\"post\" >");
				printf("<textarea name=\"contenu_reponse\" cols=\"99\" rows=\"20\"> </textarea>");
				printf("<input type=\"submit\" value=\"Répondre\" class=\"bouton_warning\" valign=\"top\">");
			}
			else {

				printf("<br /><br /><form name=\"formulaire\" action=\"$page_sign_in&etat=send\" method=\"post\" >");
				printf("<textarea name=\"contenu_reponse\" cols=\"99\" rows=\"20\"> </textarea>");
				printf("<input type=\"submit\" value=\"Inscription\" class=\"bouton_warning\" valign=\"top\">");
			}
			printf("</form>");
			printf("</p>");
			printf("</div>");
			printf("</div><br /><br />");// fin table content question


		}

		if ($etat != "")
		{
			if(isset($_SESSION['login']))
			{



				$contenu_reponse = stripslashes($_POST['contenu_reponse']);

				$contenu_reponse = str_replace("<h3>", "<h3 class=\"reference_titre_text\">", $contenu_reponse);
				$contenu_reponse = str_replace("<strong>", "<b>", $contenu_reponse);
				$contenu_reponse = str_replace("</strong>", "</b>", $contenu_reponse);
				$contenu_reponse = str_replace("<li>", "<li>• ", $contenu_reponse);
				$today = date("Y-m-d H:i:s");

				$req="INSERT INTO reponses VALUES ('','".$id_user."','".$idq."','".$contenu_reponse."','".$today."','1')";
				$resultat = sql_executer($connexion, $req);
			}
			else {

			}
		}



		?></div>
		<!--  end table-content  -->

		<div class="clear"></div>

		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
</table>
<div class="clear">&nbsp;</div>
		<?php
		printf("<br /><p align=\"center\">Page : "); //Pour l'affichage, on centre la liste des pages
		for($i=1; $i<=$nombreDePages; $i++) //On fait notre boucle
		{
			//On va faire notre condition
			if($i==$pageActuelle) //Si il s'agit de la page actuelle...
			{
				printf("<span class=\"pagination1\">$i</span>");
			}
			else //Sinon...
			{
				printf("<span class=\"pagination2\"><a href=\"index.php?join=tutoriel&page=$i\">$i</a></span>");
			}
		}
		printf("</p>");
